package Offer;

/*
* 打印从1到最大的n位数  考虑大数问题, 防止溢出与复杂的进位计算,使用字符串全排列递归
* */
public class Offer7printNumbers {
    int n;
    StringBuffer sb;
    char[] chars,num;
    public String printNumbers(int n) {
        this.n=n;
        sb = new StringBuffer();
        chars=new char[]{'0','1'};
        num=new char[n];
        dfs(0);
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }

    private void dfs(int x) {
        if(x==n){
            sb.append(String.valueOf(x)+',');
            return;
        }
        for (char aChar : chars) {
            num[x]=aChar;
            dfs(x+1);
        }
    }
}
